package com.yk.anima.controller;

import com.yk.anima.api.ProductsHheepApi;
import com.yk.anima.pojo.ProductsHheep;
import com.yk.anima.response.QueryResponseResult;
import com.yk.anima.response.ResponseResult;
import com.yk.anima.servlet.ProductsHheepServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaokai
 * @create 2021-05-13 22:37:17
 * @desc...对羊进行管理
 */
@RestController
@RequestMapping("/heep")
public class ProductsHheepController implements ProductsHheepApi {

    @Autowired
    ProductsHheepServlet productsHheepServlet;

    /**
     * @param
     * @return java.util.List<com.yk.anima.pojo.ProductsHheep>
     * @Author xiaoKai
     * @Description 查询所有羊类
     * @Date 9:20 2021/5/15
     */
    @Override
    @GetMapping("/findAll")
    public List<ProductsHheep> findAll() {
        return productsHheepServlet.findAll();
    }

    /**
     * @param id
     * @return com.yk.anima.pojo.ProductsHheep
     * @Author xiaoKai
     * @Description 根据ID查询羊
     * @Date 9:23 2021/5/15
     */
    @Override
    @GetMapping("/findById/{id}")
    public ProductsHheep findById(@PathVariable("id") int id) {
        return productsHheepServlet.findById(id);
    }

    /**
     * @param productsHheep
     * @return com.yk.anima.response.ResponseResult
     * @Author xiaoKai
     * @Description 添加羊类
     * @Date 9:25 2021/5/15
     */
    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody ProductsHheep productsHheep) {
        return productsHheepServlet.save(productsHheep);
    }

    /**
     * @param id
     * @param productsHheep
     * @return com.yk.anima.response.ResponseResult
     * @Author xiaoKai
     * @Description 根据Id修改羊
     * @Date 9:32 2021/5/15
     */
    @Override
    @PutMapping("/update/{id}")
    public ResponseResult update(@PathVariable("id") int id, @RequestBody ProductsHheep productsHheep) {
        return productsHheepServlet.update(id,productsHheep);
    }

    /**
     * @Author xiaoKai
     * @Description 根据ID删除羊
     * @Date 9:42 2021/5/15
     * @param id
     * @return com.yk.anima.response.ResponseResult
     */
    @Override
    @DeleteMapping("/deleteById/{id}")
    public ResponseResult deneteById(@PathVariable("id") int id) {
        return productsHheepServlet.deleteById(id);
    }

    @Override
    @GetMapping("/findByPage/{page}/{size}")
    public QueryResponseResult findByPage(@PathVariable("page") int page,
                                          @PathVariable("size") int size, String name) {

        return productsHheepServlet.findByPage(page,size,name);
    }
}
